/*
 * @Description: 顶部tabs组件
 * @Author: Chenx
 * @Date: 2023-04-18 15:33:07
 * @LastEditors: Chenx
 * @LastEditTime: 2023-04-19 09:41:13
 */
import { defineStore } from 'pinia'
interface tabVo {
  path: string,
  label: string
}
export const tabStore = defineStore('tabStore', {
  state: () => {
    return {
      opendTabs: [] as Array<tabVo>,
      activePath: ''
    }
  },
  getters: {
    getOpendTabs: (state) => {
      return state.opendTabs
    },
    getActivePath: (state) => {
      return state.activePath
    }
  },
  actions: {
    addOpendTabs (tab: tabVo) {
      this.opendTabs.push(tab)
    },
    deleteTab (index: number) {
      this.opendTabs.splice(index, 1)
    },
    setActivePath (path: string) {
      this.activePath = path
    }
  },
  persist: {
    enabled: true,
    strategies: [{ storage: localStorage, paths: ['opendTabs'] }]
  }
})
